package com.ym.medical.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.PatientDetailDao;
import com.ym.medical.domain.entity.PatientDetailEntity;
import com.ym.medical.domain.param.PatientDetailParam;
import com.ym.medical.enums.PatientDetailRelationEnum;
import com.ym.medical.service.IPatientDetailSV;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 患者家人Service业务层处理
 *
 * @author ym
 * @date 2020-08-21
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PatientDetailSVImpl extends BaseSVImpl<PatientDetailEntity, PatientDetailDao> implements IPatientDetailSV {

	/**
	 * 更新
	 */
	@Override
	public void update(PatientDetailEntity patientDetail) {
		this.updateById(patientDetail);
	}

	/**
	 * Load查询
	 */
	@Override
	public PatientDetailEntity findById(long id) {
		return this.selectById(id);
	}


	/**
	 * 用户id 查询患者信息
	 *
	 * @param userId
	 * @return
	 */
	@Override
	public PatientDetailEntity selectByUserId(Long userId) {
		PatientDetailEntity p = this.selectOne(
				PatientDetailEntity.builder().userId(userId)
						.relation(PatientDetailRelationEnum.I_AM.getKey()).build());
		return p;
	}

	/***
	 * 患者id 查询患者详情
	 * @param patientId
	 * @return
	 */
	@Override
	public PatientDetailEntity selectBypatientId(Long patientId) {
		PatientDetailEntity p = this.selectById(patientId);
		return p;
	}

	/**
	 * 查询患者列表
	 *
	 * @param model
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@Override
	public PageInfo<PatientDetailEntity> listPagePatient(PatientDetailParam model, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<PatientDetailEntity> patientDetails = mapper.listPagePatient(model);
		return new PageInfo<>(patientDetails);
	}

	@Override
	public PatientDetailEntity selectByOrderId(Long orderId) {
		return mapper.selectByOrderId(orderId);
	}
}
